package cn.shujuhai.meeting.controller;

import cn.shujuhai.common.aop.SysLog;
import cn.shujuhai.common.domain.PageRequest;
import cn.shujuhai.common.pluging.data.ResultVo;
import cn.shujuhai.meeting.domain.Equipment;
import cn.shujuhai.meeting.service.EquipmentService;
import com.github.pagehelper.PageInfo;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: NiuYaHu
 * @Date: 2025/6/16 10:29
 * @Description:
 **/
@RestController
@RequestMapping("/meeting/equipment")
@RequiredArgsConstructor
public class EquipmentController {
    final EquipmentService equipmentService;

    /**
     * 查询设备列表
     *
     * @param roomId      会议室Id
     * @param pageRequest
     * @return 查询的设备列表
     */
    @SysLog(value = "会议室设备列表查询", operationType = "查询", module = "设备模块")
    @GetMapping("/list")
    public ResultVo<PageInfo<Equipment>> getEquipmentList
    (@Validated String equipmentName, @Valid PageRequest pageRequest, Long roomId) {
        return this.equipmentService.getEquipmentPageInfo(equipmentName, pageRequest.getPageNum(), pageRequest.getPageSize(), roomId);
    }

    /**
     * 新增
     *
     * @param equipment 新增设备
     * @return 新增设备
     */
    @SysLog(value = "新增设备", operationType = "新增", module = "设备模块")
    @PostMapping("/add")
    public ResultVo<?> save(@RequestBody @Validated Equipment equipment) {
        return this.equipmentService.add(equipment);
    }

    /**
     * 设备编辑
     *
     * @param equipment 编辑设备对象
     * @return 更新设备对象
     */
    @SysLog(value = "设备编辑", operationType = "编辑", module = "设备模块")
    @PostMapping("/update")
    public ResultVo<Equipment> update(@RequestBody @Validated Equipment equipment) {
        return this.equipmentService.edit(equipment);
    }

    /**
     * 删除设备
     *
     * @param equipmentId 设备Id
     * @return 删除响应结果
     */
    @SysLog(value = "删除设备", operationType = "删除", module = "设备模块")
    @PostMapping("/delete/{equipmentId}")
    public ResultVo<Equipment> delete(@PathVariable Integer equipmentId) {
        return this.equipmentService.removeId(equipmentId);
    }

    /**
     * 根据会议室Id查询设备列表
     *
     * @param roomId 会议室Id
     * @return 设备列表
     */
    @GetMapping("/equipmentListByRoomId")
    public ResultVo<?> equipmentListByRoomId(Long roomId) {
        return this.equipmentService.equipmentListByRoomId(roomId);
    }
}
